home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / arpdump.c < prev    next >
C/C++ Source or Header  |  1991-03-29  |  2KB  |  79 lines

  1. /* @(#) $Header: arpdump.c,v 1.5 91/03/28 19:38:59 deyke Exp $ */
  2.  
  3. /* ARP packet tracing routines
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6. #include <stdio.h>
  7. #include "global.h"
  8. #include "mbuf.h"
  9. #include "arp.h"
  10. #include "netuser.h"
  11. #include "trace.h"
  12.  
  13. void
  14. arp_dump(fp,bpp)
  15. FILE *fp;
  16. struct mbuf **bpp;
  17. {
  18.     struct arp arp;
  19.     struct arp_type *at;
  20.     int is_ip = 0;
  21.     char tmp[25];
  22.  
  23.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  24.         return;
  25.     fprintf(fp,"ARP: len %d",len_p(*bpp));
  26.     if(ntoharp(&arp,bpp) == -1){
  27.         fprintf(fp," bad packet\n");
  28.         return;
  29.     }
  30.     if(arp.hardware < NHWTYPES)
  31.         at = &Arp_type[arp.hardware];
  32.     else
  33.         at = NULLATYPE;
  34.  
  35.     /* Print hardware type in Ascii if known, numerically if not */
  36.     fprintf(fp," hwtype %s",smsg(Arptypes,NHWTYPES,arp.hardware));
  37.  
  38.     /* Print hardware length only if unknown type, or if it doesn't match
  39.      * the length in the known types table
  40.      */
  41.     if(at == NULLATYPE || arp.hwalen != at->hwalen)
  42.         fprintf(fp," hwlen %u",arp.hwalen);
  43.  
  44.     /* Check for most common case -- upper level protocol is IP */
  45.     if(at != NULLATYPE && arp.protocol == at->iptype){
  46.         fprintf(fp," prot IP");
  47.         is_ip = 1;
  48.     } else {
  49.         fprintf(fp," prot 0x%x prlen %u",arp.protocol,arp.pralen);
  50.     }
  51.     switch(arp.opcode){
  52.     case ARP_REQUEST:
  53.         fprintf(fp," op REQUEST");
  54.         break;
  55.     case ARP_REPLY:
  56.         fprintf(fp," op REPLY");
  57.         break;
  58.     case REVARP_REQUEST:
  59.         fprintf(fp," op REVERSE REQUEST");
  60.         break;
  61.     case REVARP_REPLY:
  62.         fprintf(fp," op REVERSE REPLY");
  63.         break;
  64.     default:
  65.         fprintf(fp," op %u",arp.opcode);
  66.         break;
  67.     }
  68.     fprintf(fp,"\n");
  69.     fprintf(fp,"sender");
  70.     if(is_ip)
  71.         fprintf(fp," IPaddr %s",inet_ntoa(arp.sprotaddr));
  72.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.shwaddr));
  73.  
  74.     fprintf(fp,"target");
  75.     if(is_ip)
  76.         fprintf(fp," IPaddr %s",inet_ntoa(arp.tprotaddr));
  77.     fprintf(fp," hwaddr %s\n",at->format(tmp,arp.thwaddr));
  78. }
  79.